package com.bit.demo.mapper;

import com.bit.demo.model.BookInfo;
import com.bit.demo.model.PageRequest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BookInfoMapper {

    @Insert("insert into book_info (book_name, author, count, price, publish, status) values " +
            " (#{bookName}, #{author}, #{count}, #{price}, #{publish}, #{status})")
    Integer addBook(BookInfo bookInfo);

    @Select("select count(1) from book_info")
    Integer count();

    @Select("select * from book_info where `status` != 0 order by id asc limit #{offset}, #{pageSize}")
    List<BookInfo> getListByPage(PageRequest pageRequest);

    @Select("select id, book_name, author, count, price, publish, `status`, create_time, update_time" +
            " from book_info where id = #{id} and `status` != 0")
    BookInfo queryBookById(Integer id);

    void updateBook(BookInfo bookInfo);

    @Update("update book_info set `status` = 0 where id = #{id}")
    Integer deleteBook(Integer id);

    void batchDeleteBook(List<Integer> ids);
}
